package com.hub.controller;

import com.hub.utils.ApiResultObject;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * @author hub
 */
public class BaseController {
    protected ApiResultObject checkValidResult(BindingResult bindingResult) {

        if(bindingResult.hasErrors()){
            StringBuilder errorMessage = new StringBuilder();
            for (ObjectError error : bindingResult.getAllErrors()) {
                errorMessage.append(error.getDefaultMessage() + "  ");
            }
            return ApiResultObject.failed(-10000,"参数错误:" + errorMessage.toString());
        }
        else
            return ApiResultObject.success("");
    }
}
